I am trying to see how much of the variance of a variable Y occurs between groups of a categorical variable X, and how much is within groups of X. For that, I thought of computing the sample analog to the law of total variance [ V(Y) = E(V(Y|X)) + V(E(Y|X)]. Is there a simple way to compute this in Stata?
This is how fas as I got, in a reproducible example:
This is how fas as I got, in a reproducible example:
Code:
sysuse auto, clear *V(Y) sum price *V(E(Y|X) : un reg on FEs and calculte their average egen make2=group(make) reg price i.make2, nocons matrix FEs = e(b) scalar V_FEs= mean(FEs) // this is giving an the erro message unknown function mean() *E(V(Y|X)) predict y_resid, resid *somehow compute the by group variance and average them